#pragma once

#include "stdafx.h"

#pragma region Http Entity

//entity-header  = Allow                    ; Section 14.7
//               | Content-Encoding         ; Section 14.11
//               | Content-Language         ; Section 14.12
//               | Content-Length           ; Section 14.13
//               | Content-Location         ; Section 14.14
//               | Content-MD5              ; Section 14.15
//               | Content-Range            ; Section 14.16
//               | Content-Type             ; Section 14.17
//               | Expires                  ; Section 14.21
//               | Last-Modified            ; Section 14.29
//               | extension-header

//extension-header = message-header
class CHttpEntityHeader {
public:
	std::string Encoding;
	std::string Length;
};
class CHttpEntityBody {
public:
};
class CHttpEntity {
public:
	BOOL PreProcess(std::string data);

	CHttpEntityHeader	mEntityHeader;
	CHttpEntityBody		mEntityBody;
	std::map<std::string, std::string> mColums;
};
#pragma endregion


#pragma region Http Request


//  Request-Line   = Method SP Request-URI SP HTTP-Version CRLF
class CHttpRequestLine {
public:
	BOOL PreProcess(std::string data);
	std::string RequestContent();
	std::string RequestPostfix();

	typedef enum {
		mth_OPTIONS = 0,
		mth_GET,
		mth_HEAD,
		mth_POST,
		mth_PUT,
		mth_DELETE,
		mth_TRACE,
		mth_CONNECT
	} HTTPMethodT;
	//Method = "OPTIONS"; Section 9.2
	//	| "GET"; Section 9.3
	//	| "HEAD"; Section 9.4
	//	| "POST"; Section 9.5
	//	| "PUT"; Section 9.6
	//	| "DELETE"; Section 9.7
	//	| "TRACE"; Section 9.8
	//	| "CONNECT"; Section 9.9
	//	| extension - method
	//	extension - method = token

	HTTPMethodT enuMethod;
	std::string strMethod;

	//       Request-URI    = "*" | absoluteURI | abs_path | authority
	std::string URI;
	std::string version;
	/*If Request - URI is an absoluteURI, the host is part of the
	Request - URI.Any Host header field value in the request MUST be
	ignored.*/

	std::string mLine;
};


//Request       = Request-Line              ; Section 5.1
//                *(( general-header        ; Section 4.5
//                 | request-header         ; Section 5.3
//                 | entity-header ) CRLF)  ; Section 7.1
//                CRLF
//                [ message-body ]          ; Section 4.3
//request-header = Accept                   ; Section 14.1
//               | Accept-Charset           ; Section 14.2
//               | Accept-Encoding          ; Section 14.3
//               | Accept-Language          ; Section 14.4
//               | Authorization            ; Section 14.8
//               | Expect                   ; Section 14.20
//               | From                     ; Section 14.22
//               | Host                     ; Section 14.23
//               | If-Match                 ; Section 14.24
//| If-Modified-Since        ; Section 14.25
//| If-None-Match            ; Section 14.26
//| If-Range                 ; Section 14.27
//| If-Unmodified-Since      ; Section 14.28
//| Max-Forwards             ; Section 14.31
//| Proxy-Authorization      ; Section 14.34
//| Range                    ; Section 14.35
//| Referer                  ; Section 14.36
//| TE                       ; Section 14.39
//| User-Agent               ; Section 14.43
class CHttpRequestHeader {
public:
	BOOL PreProcess(std::string data);

	std::string Host;
};

class CHttpRequest
{
public:
	BOOL PreProcess(const uchar * payload, UINT32 payloadlen);

	CHttpRequestLine	mRequestLine;
	CHttpRequestHeader	mRequestHeader;
	CHttpEntity			mRequestEntity;
};

#pragma endregion


#pragma region Http Response

//Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
class CHttpResponseLine {
public:
	BOOL PreProcess(std::string data);
	std::string version;
	//- 1xx: Informational - Request received, continuing process

	//- 2xx: Success - The action was successfully received,
	//  understood, and accepted

	//- 3xx: Redirection - Further action must be taken in order to
	//  complete the request

	//- 4xx: Client Error - The request contains bad syntax or cannot
	//  be fulfilled

	//- 5xx: Server Error - The server failed to fulfill an apparently
	//  valid request
	std::string StatusCode;
	//  Status-Code    =
	//        "100"  ; Section 10.1.1: Continue
	//      | "101"  ; Section 10.1.2: Switching Protocols
	//      | "200"  ; Section 10.2.1: OK
	//      | "201"  ; Section 10.2.2: Created
	//      | "202"  ; Section 10.2.3: Accepted
	//      | "203"  ; Section 10.2.4: Non-Authoritative Information
	//      | "204"  ; Section 10.2.5: No Content
	//      | "205"  ; Section 10.2.6: Reset Content
	//      | "206"  ; Section 10.2.7: Partial Content
	//      | "300"  ; Section 10.3.1: Multiple Choices
	//      | "301"  ; Section 10.3.2: Moved Permanently
	//      | "302"  ; Section 10.3.3: Found
	//      | "303"  ; Section 10.3.4: See Other
	//      | "304"  ; Section 10.3.5: Not Modified
	//      | "305"  ; Section 10.3.6: Use Proxy
	//      | "307"  ; Section 10.3.8: Temporary Redirect
	//      | "400"  ; Section 10.4.1: Bad Request
	//      | "401"  ; Section 10.4.2: Unauthorized
	//      | "402"  ; Section 10.4.3: Payment Required
	//      | "403"  ; Section 10.4.4: Forbidden
	//      | "404"  ; Section 10.4.5: Not Found
	//      | "405"  ; Section 10.4.6: Method Not Allowed
	//      | "406"  ; Section 10.4.7: Not Acceptable
	//		| "407"  ; Section 10.4.8: Proxy Authentication Required
	//      | "408"  ; Section 10.4.9: Request Time-out
	//      | "409"  ; Section 10.4.10: Conflict
	//      | "410"  ; Section 10.4.11: Gone
	//      | "411"  ; Section 10.4.12: Length Required
	//      | "412"  ; Section 10.4.13: Precondition Failed
	//      | "413"  ; Section 10.4.14: Request Entity Too Large
	//      | "414"  ; Section 10.4.15: Request-URI Too Large
	//      | "415"  ; Section 10.4.16: Unsupported Media Type
	//      | "416"  ; Section 10.4.17: Requested range not satisfiable
	//      | "417"  ; Section 10.4.18: Expectation Failed
	//      | "500"  ; Section 10.5.1: Internal Server Error
	//      | "501"  ; Section 10.5.2: Not Implemented
	//      | "502"  ; Section 10.5.3: Bad Gateway
	//      | "503"  ; Section 10.5.4: Service Unavailable
	//      | "504"  ; Section 10.5.5: Gateway Time-out
	//      | "505"  ; Section 10.5.6: HTTP Version not supported
	//      | extension-code
	// extension-code = 3DIGIT
	// Reason-Phrase  = *<TEXT, excluding CR, LF>
	std::string reason;
};


class CHttpResponseHeader {
public:
	//response-header = Accept-Ranges           ; Section 14.5
	//                | Age                     ; Section 14.6
	//                | ETag                    ; Section 14.19
	//                | Location                ; Section 14.30
	//                | Proxy-Authenticate      ; Section 14.33
	//				  | Retry-After             ; Section 14.37
	//                | Server                  ; Section 14.38
	//                | Vary                    ; Section 14.44
	//                | WWW-Authenticate        ; Section 14.47

};

//Response      = Status-Line               ; Section 6.1
//                *(( general-header        ; Section 4.5
//                 | response-header        ; Section 6.2
//                 | entity-header ) CRLF)  ; Section 7.1
//                CRLF
//                [ message-body ]          ; Section 7.2
class CHttpResponse {
public:
	BOOL PreProcess(const uchar * payload, UINT32 payloadlen);

	CHttpResponseLine	mResponseLine;
	CHttpResponseHeader	mResponseHeader;
	CHttpEntity			mResponseEntity;
	UINT32				mContentLength;
	BOOL				mChunked;
};

#pragma endregion
